﻿Option Strict On

Imports System.Security.Cryptography.X509Certificates
Imports System.Net.Security

Namespace FTP
    ''' <summary>
    ''' Event arguments to facilitate the FtpClient transfer progress and complete events.
    ''' </summary>
    Public Class ValidateServerCertificateEventArgs
        Inherits EventArgs

        Private _certificate As X509Certificate2
        Private _chain As X509Chain
        Private _policyErrors As SslPolicyErrors
        Private _isCertificateValid As Boolean

        ''' <summary>
        ''' ValidateServerCertificateEventArgs constructor.
        ''' </summary>
        ''' <param name="certificate">X.509 certificate object.</param>
        ''' <param name="chain">X.509 certificate chain.</param>
        ''' <param name="policyErrors">SSL policy errors.</param>
        Public Sub New(ByVal certificate As X509Certificate2, ByVal chain As X509Chain, ByVal policyErrors As SslPolicyErrors)
            _certificate = certificate
            _chain = chain
            _policyErrors = policyErrors
        End Sub

        ''' <summary>
        ''' The X.509 version 3 server certificate.
        ''' </summary>
        Public ReadOnly Property Certificate() As X509Certificate2
            Get
                Return _certificate
            End Get
        End Property

        ''' <summary>
        ''' Server chain building engine for server certificate.
        ''' </summary>
        Public ReadOnly Property Chain() As X509Chain
            Get
                Return _chain
            End Get
        End Property

        ''' <summary>
        ''' Enumeration representing SSL (Secure Socket Layer) errors.
        ''' </summary>
        Public ReadOnly Property PolicyErrors() As SslPolicyErrors
            Get
                Return _policyErrors
            End Get
        End Property

        ''' <summary>
        ''' Boolean value indicating if the server certificate is valid and can
        ''' be accepted by the FtpClient object.
        ''' </summary>
        ''' <remarks>
        ''' Default value is false which results in certificate being rejected and the SSL
        ''' connection abandoned.  Set this value to true to accept the server certificate 
        ''' otherwise the SSL connection will be closed.
        ''' </remarks>
        Public Property IsCertificateValid() As Boolean
            Get
                Return _isCertificateValid
            End Get
            Set(ByVal value As Boolean)
                _isCertificateValid = value
            End Set
        End Property
    End Class
End Namespace